import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () =>import("../views/home/Home")
const Category = () =>import("../views/category/Category")
const Cart = () =>import("../views/cart/Cart")
const Profile = () =>import("../views/profile/Profile")
const HomeSwiper = () =>import("../views/profile/Profile")
const Detail = () =>import("../views/detail/Detail")

// 1.安装插件
Vue.use(VueRouter)

// 2.创建路由对象
const routes = [
  {
    path: '',
    redirect: '/home.html'
  },
  {
    path: '/home.html',
    name: 'home',
    component: Home
  },
  {
    path: '/Category.html',
    name: 'category',
    component: Category
  },
  {
    path: '/Cart.html',
    name: 'cart',
    component: Cart
  },
  {
    path: '/Profile.html',
    name: 'profile',
    component: Profile
  },
  {
    path: '/HomeSwiper.html',
    name: 'homeswiper',
    component: HomeSwiper
  },
  {
    path: '/Detail.html',
    name: 'detail',
    component: Detail
  }
]
//多次点击错误处理
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
//获取原型对象上的replace函数
const originalReplace = VueRouter.prototype.replace
//修改原型对象中的push方法
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.VUE_ROUTER_BASE,
  routes,
})

// 3.导出
export default router
